﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQLServerHealthCheck.Model;
using System.Windows.Threading;
using System.Data.SqlClient;
using System.Data;
using AG.Utilities;


namespace SQLServerHealthCheck.SQLServer
{
    public delegate void IsSQLServerAccessible(String ConnString);
    
    public delegate void InstanceStatusResult(bool accessible);
    
    public class CheckInstanceStatusWorker:AsyncUtils.AsyncOperation
    {
        private string connString="";

        public event InstanceStatusResult AccessiblityResult;

        public CheckInstanceStatusWorker(DispatcherObject target,String ConnString)
            : base(target)
        {
            connString = ConnString;
        }

        protected override void DoWork()
        {
            IsSQLServerAccessible runStatusCheck = new IsSQLServerAccessible(IsSQLServerAccessible);
            runStatusCheck.BeginInvoke(connString, null, null);
        }
    
       public void IsSQLServerAccessible(string strconn)
        {
            bool result = CollectServerAndServiceData.IsSQLServerAccessible(strconn);

            FireStatusUpdateEvent(result);
        }
    
        private void FireStatusUpdateEvent(bool result)
        {
            Object[] param = new Object[] { result };

            FireAsync(AccessiblityResult, param);
        
        
        }
    
    }



}
